import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const message 				= $Lazy.file(()=>import('@antd/message'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
const $time 				= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		result: {},
		// 搜索表单列表
		forms : [
			{ label: '统计时间',		names: ['start_at','end_at'], 	name:'jz-time',		type:'date-range' },
			{ label: '科室',			name: 'parent_project_id',		type: 'select', loading:true, idStr:'uuid' },
			{ label: '岗位',			name: 'project_id',				type: 'select', loading:true },
		],
	}
	
	model = {}
	query = { is_refresh:0 }
	
	componentDidMount(){
		this.query = {}
		this.getSelect()
		// 设置时间默认值
		$time.then(f=>{
			const arr = f.duration['2-9-9']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = {...this.model, ...$fn.copy(this.resetModel)}
			if(window.isInit){
				this.fetch()
			}
		})
	}
	
	//获取下拉数据  
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow( forms, 'parent_project_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = param => window.$http.pull(this,'st-spec-num/index', { param: {...this.query, ...this.model, ...param}, paging:true, dataName:null }).then(data=>{
		this.setState({ data: data.items, result: data })
		if(param && param.is_refresh === 1){
			message.then(f=>f.success('重新统计成功'))
		}
	})
	
	// 表单
	cols = [
		{ title: '科室', 			dataIndex: 'parent_project_name', 		width:200 },
		{ title: '岗位', 			dataIndex: 'project_name', 				width:150 },
		{ title: '资料待完善', 		dataIndex: 'wait_case_info', 			...$fn.table.num },
		{ title: '待接收条码', 		dataIndex: 'wait_box_spec', 			...$fn.table.num },
		{ title: '待分发', 			dataIndex: 'wait_spec_status', 			...$fn.table.num },
		{ title: '待分发项目数量', 	dataIndex: 'sp_kind_num', 				...$fn.table.num },
		{ title: '待上架完成', 		dataIndex: 'wait_shelf', 				...$fn.table.num },
		{ title: '待领取', 			dataIndex: 'wait_receive', 				...$fn.table.num },
		{ title: '待提交', 			dataIndex: 'wait_ts_submit', 			...$fn.table.num },
		{ title: '待审核', 			dataIndex: 'wait_ts_audit', 			...$fn.table.num },
		{ title: '待批准', 			dataIndex: 'wait_ts_approve', 			...$fn.table.num },
	]
	// 操作按钮
	controls = () => {
		return [
			Controls.click.call(this, '重新统计', ()=> this.fetch({ is_refresh: 1}) ),		// 重新统计
			Controls.exports.call(this, 'st-spec-num/index'),			// 导出
		]
	}
	
	render(){
		const { result } = this.state
		return (
			<>
				<Page title='待接收标本量统计' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this, { timeStr:'2-9-9' }) }
					{/* 表格 */}
					{ Table.call(this,
						{isInit:window.isInit, suffix: (
							<>
								<div className='ml10 g9'>待录入项目标本数 <b className='f14 c0'>{result?.wait_spec_entry}</b></div>
								<div className='ml10 g9'>待接收标本数 <b className='f14 c0'>{result?.wait_spec_receive}</b></div>
								<div className='ml10 g9'>资料待完善总计 <b className='f14 c0'>{result?.wait_case_info}</b></div>
								<div className='ml10 g9'>待分发项目总计 <b className='f14 c0'>{result?.wait_spec_status}</b></div>
								<div className='ml10 g9'>待上架完成总计 <b className='f14 c0'>{result?.wait_shelf}</b></div>
								<div className='ml10 g9'>待领取总计 <b className='f14 c0'>{result?.wait_receive}</b></div>
								<div className='ml10 g9'>待提交总计 <b className='f14 c0'>{result?.wait_ts_submit}</b></div>
								<div className='ml10 g9'>待审核总计 <b className='f14 c0'>{result?.wait_ts_audit}</b></div>
								<div className='ml10 g9'>待批准总计 <b className='f14 c0'>{result?.wait_ts_approve}</b></div>
							</>
						)
						})
					}
				</Page>
			</>
		)
	}
}

export default Index